package com.example.demo.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author Scott Yan
 * @date 2020/07/21
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ResultDto {
    private Boolean success;
    private String message;
    private ResultCode code;
    private Object data;

    public enum ResultCode {
        /**
         * success
         */
        SUCCESS("2000"),
        SERVER_ERROR("5000"),
        ARGUMENT_INVALID("5001"),
        DATABASE_ERROR("5002"),
        UNKNOWN_ERROR("5009");

        private String code;
        ResultCode(String codeParam) {
            code = codeParam;
        }

        public String getCode() {
            return code;
        }
    }

    public static ResultDto success() {
        return ResultDto.builder()
                .success(true)
                .code(ResultCode.SUCCESS)
                .message("")
                .build();
    }
    public static ResultDto success(Object data) {
        return ResultDto.builder()
                .data(data)
                .success(true)
                .code(ResultCode.SUCCESS)
                .message("")
                .build();
    }

    public static ResultDto error(ResultCode code, String message){
        return ResultDto.builder()
                .success(false)
                .code(code)
                .message(message)
                .build();
    }
}
